let t = require;
let e = module
let o = e.exports;
o.default = e.exports;

'use strict';
console.log("start");
var _n60,
    i =
        (this && this.__extends) ||
        ((_n60 = function n(t, e) {
            return (_n60 =
                Object.setPrototypeOf ||
                ({
                    __proto__: []
                }
                    instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) {
                        Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                    }
                })(t, e);
        }),
            function (t, e) {
                function o() {
                    this.constructor = t;
                }
                _n60(t, e),
                    (t.prototype =
                        null === e ?
                            Object.create(e) :
                            ((o.prototype = e.prototype), new o()));
            }),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var i,
                r = arguments.length,
                a =
                    r < 3 ?
                        e :
                        null === n ?
                            (n = Object.getOwnPropertyDescriptor(e, o)) :
                            n;
            if (
                'object' ==
                (typeof Reflect === 'undefined' ?
                    'undefined' :
                    typeof (Reflect)) &&
                'function' == typeof Reflect.decorate
            )
                a = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--) {
                    (i = t[s]) &&
                        (a = (r < 3 ? i(a) : r > 3 ? i(e, o, a) : i(e, o)) || a);
                }
            return r > 3 && a && Object.defineProperty(e, o, a), a;
        };
Object.defineProperty(o, '__esModule', {
    value: !0
}),
    (o.CardMrg = o.CardSlotInfo = void 0);
var a = t('AbsInfo'),
    s = t('CardCfg'),
    c = t('CardInfo'),
    l = t('BagMrg'),
    u = t('AbsObject'),
    h = t('ConstantCfg'),
    p = cc._decorator,
    f = p.ccclass,
    d =
        (p.property,
            (function (t) {
                function e(e, o) {
                    var n = t.call(this) || this;
                    return (n._adVideoCount = e), (n._maxAdVideoCount = o), n;
                }
                return (
                    i(e, t),
                    (e.prototype.open = function () {
                        this._adVideoCount > 0 &&
                            (this._adVideoCount--, this.emit(a.InfoEvent.StateChanged));
                    }),
                    Object.defineProperty(e.prototype, 'isOpen', {
                        get: function get() {
                            return this._adVideoCount <= 0;
                        },
                        enumerable: !1,
                        configurable: !0
                    }),
                    Object.defineProperty(e.prototype, 'adVideoCount', {
                        get: function get() {
                            return this._adVideoCount;
                        },
                        enumerable: !1,
                        configurable: !0
                    }),
                    Object.defineProperty(e.prototype, 'maxAdVideoCount', {
                        get: function get() {
                            return this._maxAdVideoCount;
                        },
                        enumerable: !1,
                        configurable: !0
                    }),
                    Object.defineProperty(e.prototype, 'card', {
                        get: function get() {
                            return this._card;
                        },
                        set: function set(t) {
                            this._card != t &&
                                (this._card && (this._card.isBattle = !1),
                                    t && (t.isBattle = !0),
                                    (this._card = t),
                                    this.emit(a.InfoEvent.StateChanged));
                        },
                        enumerable: !1,
                        configurable: !0
                    }),
                    Object.defineProperty(e.prototype, 'data', {
                        get: function get() {
                            return {
                                ad: this._adVideoCount,
                                id: this._card ? this._card.cardId : 0
                            };
                        },
                        enumerable: !1,
                        configurable: !0
                    }),
                    e
                );
            })(a.default));
o.CardSlotInfo = d;
var g = (function (t) {
    function e() {
        return (null !== t && t.apply(this, arguments)) || this;
    }
    var o;
    return (
        i(e, t),
        (o = e),
        Object.defineProperty(e, 'ins', {
            get: function get() {
                return null == o._ins && (o._ins = new o()), this._ins;
            },
            enumerable: !1,
            configurable: !0
        }),
        (e.prototype.init = function (t) {
            // 初始化物品列表和卡槽列表
            this._items = [];
            this._slots = [];

            // 从传入的配置数据 t 中初始化卡片信息
            if (t && t.cards) {
                // 遍历 CardCfg 中的所有卡片配置
                for (let cardIndex = 0; cardIndex < s.CardCfg.ins.cards.length; cardIndex++) {
                    const cardConfig = s.CardCfg.ins.cards[cardIndex];
                    const cardData = t.cards[cardConfig.cardId];
                    // 创建新的卡片信息实例，若有等级数据则使用，否则使用配置默认等级
                    const cardInfo = new c.CardInfo(
                        cardConfig.cardId,
                        cardData && cardData.lv !== null ? cardData.lv : cardConfig.level
                    );
                    // 设置卡片是否拥有状态
                    cardInfo.own = cardData ? cardData.own : false;
                    // 添加卡片信息到物品列表
                    this.addInfo(cardInfo);
                }
            } else {
                // 若没有传入卡片数据，使用默认配置初始化卡片信息
                for (let cardIndex = 0; cardIndex < s.CardCfg.ins.cards.length; cardIndex++) {
                    const cardConfig = s.CardCfg.ins.cards[cardIndex];
                    const cardInfo = new c.CardInfo(cardConfig.cardId, cardConfig.level);
                    // 添加卡片信息到物品列表
                    this.addInfo(cardInfo);
                }
            }

            // 获取常量配置中索引为 16 的值
            const slotConfigValues = h.ConstantCfg.ins.getValues(16);
            slotConfigValues.fill(0);
            // 从传入的配置数据 t 中初始化卡槽信息
            if (t && t.opens) {
                const slotData = t.opens;
                slotData.forEach(element => {
                    element.ad = 0;
                });
                // 遍历传入的卡槽数据
                for (let slotIndex = 0; slotIndex < slotData.length; slotIndex++) {
                    const adVideoCount = slotData[slotIndex].ad;
                    const maxAdVideoCount = slotConfigValues[slotIndex];
                    // 创建新的卡槽信息实例
                    const slotInfo = new d(adVideoCount, maxAdVideoCount);
                    // 若卡槽有卡片 ID，设置对应的卡片信息
                    if (slotData[slotIndex].id > 0) {
                        slotInfo.card = this.getInfo(slotData[slotIndex].id);
                    }
                    // 添加卡槽信息到卡槽列表
                    this._slots.push(slotInfo);
                }
            } else {
                // 若没有传入卡槽数据，使用默认配置初始化卡槽信息
                for (let slotIndex = 0; slotIndex < slotConfigValues.length; slotIndex++) {
                    const adVideoCount = slotConfigValues[slotIndex];
                    const maxAdVideoCount = slotConfigValues[slotIndex];
                    // 创建新的卡槽信息实例
                    const slotInfo = new d(adVideoCount, maxAdVideoCount);
                    // 添加卡槽信息到卡槽列表
                    this._slots.push(slotInfo);
                }
            }

            // 触发物品数量变化处理函数
            this.onItemCountChangedHandler(0, 0);

        }),
        (e.prototype.execute = function (t, e) {
            if (t)
                if (e) {
                    if (!t.isBattle)
                        for (var o = 0; o < this._slots.length; o++) {
                            if (this._slots[o].isOpen && null == this._slots[o].card)
                                return (this._slots[o].card = t), !0;
                        }
                } else if (t.isBattle)
                    for (o = 0; o < this._slots.length; o++) {
                        if (this._slots[o].isOpen && this._slots[o].card == t)
                            return (this._slots[o].card = null), !0;
                    }
            return !1;
        }),
        Object.defineProperty(e.prototype, 'redDotState', {
            get: function get() {
                return this._redDotState;
            },
            enumerable: !1,
            configurable: !0
        }),
        (e.prototype.addInfo = function (t) {
            this._items.push(t),
                t.on(
                    a.InfoEvent.LevelChanged,
                    this.onLevelOrStateChangedHandler,
                    this
                ),
                t.on(
                    a.InfoEvent.StateChanged,
                    this.onLevelOrStateChangedHandler,
                    this
                ),
                l.BagMrg.ins.addCountEvent(
                    t.itemId,
                    this.onItemCountChangedHandler,
                    this
                );
        }),
        (e.prototype.getInfo = function (t) {
            for (var e = 0; e < this._items.length; e++) {
                if (this._items[e].cardId == t) return this._items[e];
            }
            return null;
        }),
        (e.prototype.getInfoByItem = function (t) {
            for (var e = 0; e < this._items.length; e++) {
                var o = this._items[e];
                if (o.itemId == t) return o;
            }
            return null;
        }),
        (e.prototype.onItemCountChangedHandler = function (t, e) {
            var o,
                n = this.getInfoByItem(e);
            if (n && !n.own) {
                n.own = !0;
                for (var i = 0; i < this._slots.length; i++) {
                    var r = this._slots[i];
                    if (r.isOpen && null == r.card) {
                        r.card = n;
                        break;
                    }
                }
                o = !0;
            }
            var s = !1;
            for (i = 0; i < this._items.length; i++) {
                var c = this._items[i];
                if (
                    c.own &&
                    !c.isMaxLevel &&
                    l.BagMrg.ins.getCount(c.itemId) >= c.itemCount
                ) {
                    s = !0;
                    break;
                }
            }
            this._redDotState != s &&
                ((this._redDotState = s),
                    this.emit(a.InfoEvent.RedDotStateChanged),
                    this._bind && this._bind.setRedDotState(this._redDotState)),
                o && this.emit(a.InfoEvent.StateChanged);
        }),
        (e.prototype.setBind = function (t) {
            (this._bind = t), this._bind.setRedDotState(this._redDotState);
        }),
        (e.prototype.getData = function () {
            for (var t = {}, e = [], o = 0; o < this._items.length; o++) {
                var n = this._items[o];
                t[n.cardId] = {
                    lv: n.level,
                    own: n.own
                };
            }
            for (o = 0; o < this._slots.length; o++) {
                e.push(this._slots[o].data);
            }
            return {
                cards: t,
                opens: e
            };
        }),
        (e.prototype.newDay = function () { }),
        Object.defineProperty(e.prototype, 'items', {
            get: function get() {
                return this._items;
            },
            enumerable: !1,
            configurable: !0
        }),
        Object.defineProperty(e.prototype, 'slots', {
            get: function get() {
                return this._slots;
            },
            enumerable: !1,
            configurable: !0
        }),
        (e.prototype.onLevelOrStateChangedHandler = function () {
            this.emit(a.InfoEvent.StateChanged);
        }),
        (e.CardUpgradeEvent = 'CardUpgradeEvent'),
        (o = r([f('CardMrg')], e))
    );
})(u.AbsObject);
(o.CardMrg = g), console.log("end");
module.exports = e.exports;